<template>
	<div class="user">
		<commonUserinfo :userInfoData="{userItemIndex:itemIndex,userLeftHeight:userLeftHeight,$parent:$parent}">
			<div id="modifyPwd" class="user_main_right f_left text_center">
				<div class="user_userInfo modify_pwd color666">
					<form ref="form" :model="form">
						<dl>
							<dt class="f_left">新密码：</dt>
							<dd class="f_left"><input v-model.trim="form.newPwd" type="password"></dd>
						</dl>
						<dl>
							<dt class="f_left">确认密码：</dt>
							<dd class="f_left"><input v-model.trim="form.reNewPwd" type="password"></dd>
						</dl>
						<dl>
							<dt class="f_left">手机验证码：</dt>
							<dd class="f_left">
								<input v-model.trim="form.code" class="modify_code" type="text">
								<input type="button" :value="verifyCode" :disabled="disabled" @click="getVerifyCode" class="modify_getCode_btn text_center">
							</dd>
						</dl>
						<a class="modify_sure_btn" @click="modifyPwd(form)">保存</a>
					</form>
				</div>
			</div>
		</commonUserinfo>
	</div>
</template>

<script>
	import commonUserinfo from '../../components/c_userinfo.vue'
	export default {
		name: "modify_pwd",
		data: function() {
			return {
				itemIndex: 5,
				userLeftHeight: '',
				verifyCode: "获取短信验证码",
				disabled: false,
				form: {
					newPwd: "",
					reNewPwd: "",
					code: "",
                    v_token:""
				}
			}
		},
		mounted: function() {

		},
		methods: {
			getVerifyCode: function() {
				var that = this;
				this.common.post(this.api.getVerifyCodeUpdatePwd, {}, function(data) {
                    that.form.v_token=data.resultMap;
					that.setInter();
				}, function(error) {
					that.$message.error(error.resultMsg);
				});

			},
			setInter: function() {
				var that = this;
				var countDown = 60;
				clearInterval(timer);
				var timer = setInterval(function() {
					countDown--;
					that.verifyCode = "短信已发送（" + countDown + "）";
					that.disabled = true;
					if (countDown < 1) {
						clearInterval(timer);
						that.verifyCode = "获取短信验证码";
						that.disabled = false;
					}
				}, 1000);
			},
			modifyPwd: function(dataForm) {
				var that = this;
				if (dataForm.newPwd.trim() == "") {
					this.$message.error('请输入新密码！');
					return;
				}
				if (dataForm.reNewPwd.trim() == "") {
					this.$message.error('请再次输入新密码！');
					return;
				}
				if (dataForm.newPwd.trim() != dataForm.reNewPwd.trim()) {
					this.$message.error('两次密码输入不一致！');
					return;
				}
				if (dataForm.code.trim() == "") {
					this.$message.error('请输入验证码！');
					return;
				}
				this.common.post(this.api.resetPsersonPwd, dataForm, function(data) {
					that.common.toPage("/user_info");
				}, function(error) {
					that.$message.error(error.resultMsg);
				});
			}
		},
		components: {
			commonUserinfo
		}
	}
</script>

<style>

</style>
